/**
 * Created by liuqingling on 16/4/11.
 * {
 *  state:0/1  //state=0 未通过审批 state=1 通过审批
 * }
 */

var mongoose = require('../database/db');
var Schema = mongoose.Schema;
var userJson = {
    'state':0,//0待审批,1通过,-1是拒绝
    'name': {
        type: 'String',
        required:[true,'请您输入用户名'],
    },
    'company': {
        type: 'String',
        required:[true,'请您输入单位名称'],
    },
    'phone': {
        type: 'String',
        required:[true,'请您输入手机号码'],
        validate:{
            validator: function(v) {
                if(/^1[3|4|5|7|8]\d{9}$/.test(v)){
                    return true
                }else{
                    return false;
                }
            },
            message: '{VALUE} 无效手机号码'
        }
    },
    'email': {
        type: 'String',
        required:[true,'请您输入邮箱'],
        validate:{
            validator: function(v) {
                return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(v);
            },
            message: '{VALUE} 您的电子邮件格式不正确'
        }
    },
    'captcha':{type:'String',required:[true,'验证码不能为空']},
    'date':{type:'Date'}
};
var userSchema =  new Schema(userJson);
var User=mongoose.model('User', userSchema);
//User.schema.path('phone').validate(function(v){
//    console.log(v);
//    console.log(this);
//})
// create an export function to encapsulate the model creation
module.exports =User;